<script lang="ts" setup>
import { useUserStore } from '@/stores/user'
import { ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'

//获取存储库
const store = useUserStore()
//获取路由
const router = useRouter()
//点击退出按钮
const onLogout = () => {
  ElMessageBox.confirm('是否退出登录？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
  }).then(() => {
    //清除token
    store.removeToken()
    //跳转到登录页
    router.push('/login')
  })
}
</script>

<template>
  <el-container class="layout-container">
    <!-- 侧边栏 -->
    <el-aside width="200px">
      <div class="logo"></div>
      <el-menu
        background-color="#023"
        text-color="#fff"
        style="border-right: none"
        :default-active="router.currentRoute.value.path"
        router
      >
        <el-menu-item index="/home"> <i class="el-icon-s-home"></i> 数据概览 </el-menu-item>

        <el-menu-item index="/article"> <i class="el-icon-document"></i> 内容管理 </el-menu-item>

        <el-menu-item index="/publish"> <i class="el-icon-s-promotion"></i> 发布文章 </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <span>用户名</span>
        <el-link @click="onLogout" icon="el-icon-unlock" :underline="false">退出</el-link>
      </el-header>

      <el-main>
        <!-- 路由出口 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped lang="less">
.layout-container {
  height: 100vh;

  .el-aside {
    background-color: #023;

    .logo {
      width: 200px;
      height: 60px;
      background: #023 url('@/assets/images/logo.png') no-repeat center / 160px auto;
    }
  }

  .el-header {
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
  }
}
</style>
